#type vertex
#version 330 core
layout (location = 0) in vec2 aPos;
layout (location = 1) in vec2 aTex;

out vec2 FragTex;

uniform mat4 _model;
uniform mat4 _view;
uniform mat4 _projection;

void main()
{
    FragTex = aTex;
    gl_Position = _projection * _view * _model * vec4(aPos, 0.0, 1.0);
}

#type fragment
#version 330 core

in vec2 FragTex;

out vec4 FragColor;

uniform sampler2D _framebuffer_tex;

const float offset = 1.0 / 600.0;

void main()
{
    vec2 offsets[9] = vec2[](
    vec2(-offset, offset), // 左上
    vec2(0.0f, offset), // 正上
    vec2(offset, offset), // 右上
    vec2(-offset, 0.0f), // 左
    vec2(0.0f, 0.0f), // 中
    vec2(offset, 0.0f), // 右
    vec2(-offset, -offset), // 左下
    vec2(0.0f, -offset), // 正下
    vec2(offset, -offset)// 右下
    );

    float kernel[9] = float[](
    1, 1, 1,
    1, -8, 1,
    1, 1, 1
    );

    vec3 sampleTex[9];
    for (int i = 0; i < 9; i++)
    {
        sampleTex[i] = vec3(texture(_framebuffer_tex, FragTex.st + offsets[i]));
    }
    vec3 col = vec3(0.0);
    for (int i = 0; i < 9; i++)
    col += sampleTex[i] * kernel[i];

    float average = 0.2126 * col.r + 0.7152 * col.g + 0.0722 * col.b;
    col = average > 0.5 ? vec3(1.0) : vec3(0.0);

    FragColor = vec4(col, 1.0);
}
